﻿using UnityEngine;
using System.Collections;

public class TankAttack : MonoBehaviour {

	public GameObject shellPrefab;
	public KeyCode fireKey = KeyCode.Space;
	public float shellSpeed = 10;//子弹速度

	private Transform firePosition;
	public AudioClip shotAudio;
	// Use this for initialization
	void Start () {
		firePosition = transform.Find ("FirePosition");
	}
	
	// Update is called once per frame
	void Update () {
	
		if (Input.GetKeyDown (fireKey)) {
			AudioSource.PlayClipAtPoint(shotAudio, transform.position, 1);
			GameObject go= GameObject.Instantiate (shellPrefab, firePosition.position, firePosition.rotation) as GameObject;

			//给子弹添加速度
			go.GetComponent<Rigidbody>().velocity = go.transform.forward*shellSpeed;
		}
	}
}
